
_realname=opentimelineio
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.17.0
pkgrel=1
pkgdesc="Open Source API and interchange format for editorial timeline information (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url="http://opentimeline.io/"
msys2_repository_url='https://github.com/AcademySoftwareFoundation/OpenTimelineIO'
msys2_references=(
  'archlinux: opentimelineio'
)
license=("spdx:Apache-2.0")
depends=(
  "${MINGW_PACKAGE_PREFIX}-gcc-libs"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-cmake"
  "${MINGW_PACKAGE_PREFIX}-imath"
  "git"
)
source=("https://github.com/AcademySoftwareFoundation/OpenTimelineIO/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        "rapidjson::git+https://github.com/Tencent/rapidjson"
        "001-cmake-target-paths.patch")
sha256sums=('cdf8281c6091a18a4147295b660e13b610a6d58919a79608bf03e5359c1c2d24'
            'SKIP'
            'bab20bf5087b6f5e4263c41af094ab22b0a4584cd615a2ae6423d383ee499229')

apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying $_patch"
    patch -Nbp1 -i "${srcdir}/$_patch"
  done
}

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}

  apply_patch_with_msg \
    001-cmake-target-paths.patch

  mv -f "${srcdir}/rapidjson" "${srcdir}/${_realname}-${pkgver}/src/deps"
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  declare -a _extra_config
  if check_option "debug" "n"; then
    _extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    _extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -GNinja \
    -DOTIO_FIND_IMATH=ON \
    -DOTIO_AUTOMATIC_SUBMODULES=OFF \
    -DOTIO_DEPENDENCIES_INSTALL=OFF \
    -DOTIO_PYTHON_INSTALL=OFF \
    "${_extra_config[@]}" \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake --build .

}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake.exe --install .

  install -vDm 644 "${srcdir}"/${_realname}-${pkgver}/LICENSE.txt \
    -t "${pkgdir}${MINGW_PREFIX}/share/licenses/$_realname/"
}
